package com.fernfx.xingtan.common.base;

import android.app.Application;
import android.content.Context;

import com.fernfx.xingtan.common.entity.user.MemberEntity;
import com.fernfx.xingtan.utils.FramesInitUtil;

import java.io.Serializable;
import java.text.DecimalFormat;

/**
 * application 基类
 */
public class BaseApplication extends Application {

    private static BaseApplication sBaseApplication;
    public static MemberEntity memberEntity;
    //is log
    public static boolean IS_DEBUG = false;

    /*
     * 用于格式化金额数据
     */
    public static DecimalFormat decimalFormat = new DecimalFormat("#0.00");

    //正在使用的环境
    public static String ENVIRONMENT_URL = Environment.code.getValue();

    public static synchronized BaseApplication getInstance() {
        return sBaseApplication;
    }

    public static void setMemberEntity(MemberEntity memberEntity) {
        BaseApplication.memberEntity = memberEntity;
    }

    /*
     * 设置接口环境
     */
    public static void initEnvironment(Environment environment) {
        switch (environment) {
            case code:
                IS_DEBUG = true;
                ENVIRONMENT_URL = Environment.code.getValue();
                break;
            case test:
                IS_DEBUG = true;
                ENVIRONMENT_URL = Environment.test.getValue();
                break;
            case internet:
                IS_DEBUG = false;
                ENVIRONMENT_URL = Environment.internet.getValue();
                break;
        }
    }

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
    }

    @Override
    public void onCreate() {
        super.onCreate();
        sBaseApplication = this;
        initThirdService();
        initData();
    }

    /**
     * 初始化三方框架或者初始化服务
     */
    protected void initThirdService() {
        //融云
        FramesInitUtil.rongYun(this);
        //百度地图
        FramesInitUtil.baiduMap(this);
    }

    /**
     * 初始化操作
     */
    public void initData() {
    }

    /*
     * 测试环境,生产环境
     */
    public enum Environment {
        code("http://192.168.0.145:8080/xingtan/api/"), test("http://192.168.0.145:8080/xingtan/api/"), internet("internet");
        private final String value;

        public String getValue() {
            return value;
        }

        Environment(String value) {
            this.value = value;
        }
    }
}
